﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Windstamp.Utility.BookDownload.Common {
    /// <summary>
    /// 提示信息回调助手类
    /// </summary>
    public class PromptHelper {
        /// <summary>
        /// 提示信息回调方法集合
        /// </summary>
        public static Dictionary<string, Action<string, PromptType>> Handlers { get; private set; }

        static PromptHelper() {
            Handlers = new Dictionary<string, Action<string, PromptType>>();
        }

        /// <summary>
        /// 添加提示信息回调方法
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="handler">提示信息回调方法</param>
        public static void AddHandler(string key, Action<string, PromptType> handler) {
            Handlers.Add(key, handler);
        }

        ///// <summary>
        ///// 添加提示信息回调方法
        ///// </summary>
        ///// <param name="key">键</param>
        ///// <param name="handler">提示信息回调方法</param>
        //public static void AddHandler(string key, Action<string> handler) {
        //    Handlers.Add(key, new Action<string, PromptType>((info, type) => { handler(info); }));
        //}

        /// <summary>
        /// 删除指定提示信息回调方法
        /// </summary>
        /// <param name="key"></param>
        public static void RemoveHandler(string key) {
            Handlers.Remove(key);
        }

        /// <summary>
        /// 清空所有提示信息回调方法
        /// </summary>
        public static void ClearHandlers() {
            Handlers.Clear();
        }

        /// <summary>
        /// 替换指定键对应的提示信息回调方法
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="handler">用于替换的提示信息回调方法</param>
        public static void SetHandler(string key, Action<string, PromptType> handler) {
            Handlers[key] = handler;
        }
    }

    /// <summary>
    /// 提示消息类型
    /// </summary>
    public enum PromptType {
        /// <summary>
        /// 无类型
        /// </summary>
        None = 0,
        /// <summary>
        /// 错误
        /// </summary>
        Error = 16,
        /// <summary>
        /// 疑问
        /// </summary>
        Question = 32,
        /// <summary>
        /// 警告
        /// </summary>
        Warning = 48,
        /// <summary>
        /// 信息
        /// </summary>
        Information = 64
    }

    /// <summary>
    /// 提示消息位置
    /// </summary>
    public enum PromptPosition {
        /// <summary>
        /// 弹出提示
        /// </summary>
        Alert,

        /// <summary>
        /// 状态栏状态
        /// </summary>
        StatusStripMsg,

        /// <summary>
        /// 状态栏书名
        /// </summary>
        StatusStripBookname
    }
}
